// 开发文档：https://uniapp.dcloud.io/uniCloud/clientdb?id=action
module.exports = {
	before: async (state, event) => {
		let db = uniCloud.database();  
		let id=state.auth.uid
		let userInfo = await db.collection('uni-id-users').where({
			_id:id
		}).get({getOne:true})
		userInfo=userInfo.data[0]
		state.newData.app_id = userInfo.app_id
		if(state.auth.permission.indexOf("mall_admin")>-1){
			let shop_id=state.newData.shop_id
			if(!shop_id){
				state.newData.shop_id = userInfo.shop_id
			}else{
				/* let shopInfo = await db.collection('catering-shop').where({
					_id:shop_id,
					app_id:userInfo.app_id
				}).get({getOne:true})
				if(shopInfo.data.length==0){
					state.newData.shop_id = userInfo.shop_id
				}	 */
			}
		}else{
			state.newData.shop_id = userInfo.shop_id
		}
		state.newData.creator_name = userInfo.username
	},
	after: async (state, event, error, result) => {
		if (error) {
			throw error
		}
		return result
	}
}
